
/*$().ready(function() {
	validateRule();
});
$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function onTypeChange() {
	validateRule();
}*/

function save() {
	var productId = $('#productId').val();
	if (productId == null || productId == '') {
		parent.layer.msg("请选择商品",{icon:7});
		return;
	}
	
	$.ajax({
		cache : true,
		type : "POST",
		url : "/zhibo/manage/save",
		data : $('#zhiboAddForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				if (data.msg) {
					parent.layer.alert(data.msg)
				}else {
					window.location.href = "/";
				}
			}

		}
	});
}

$("#type").change(function(){
	var val=$("#type").val();
	if(val == 1) {
		$("#imageDiv").css('display','');
		$("#videoDiv").css('display','none');
	} else {
		$("#imageDiv").css('display','none');
		$("#videoDiv").css('display','');
	}
})

/**
 * 跳转到选择商品页面
 */
var select_product_zhibo;
function toSelectProduct() {
	select_product_zhibo = layer.open({
		id : 'select_product_zhibo',
		type : 2,
		title : '选择商品',
		maxmin : true,
		shadeClose : false,
		area : [ '95%', '95%' ],
		content : '/product/centre/toSelectProductFromCentre' // iframe的url
	});
}

function select_goods(id, title) {
	$("#title").val(title);
	$("#productId").val(id);
	layer.close(select_product_zhibo);
}

/*//选择商品
function select_goods(id,title){
	$("#title").val(title);
	$("#productId").val(id);
	var Modal=$('#myModal');
	Modal.modal('hide');
	$('.modal-backdrop').remove();
}*/

var get_goods_url="/product/manage/allProduct";
function get_goods(){
	var idOrName=$("#mgkey").val();
	if(!idOrName) return;
	$.ajax({
		url: get_goods_url,
		type:"get",
		data:{"idOrName":idOrName},
		dataType:"json",
		success:function(ret){
			if(ret != null && ret.length > 0){
				var html='';
				for(var i=0;i<ret.length;i++){
					html += '<tr><td>'+ret[i].id+'</td><td><img src='+ret[i].thumb+' style="width:50px;height:50px;"></td>' +
							'<td>'+ret[i].title+'</td>' + 
							'<td><button onclick="select_goods(\''+ret[i].id+'\',\''+ret[i].title+'\')" type="button" class="btn btn-xs btn-purple">' +
							'<span class="ace-icon fa fa-search icon-on-right bigger-110">'+
							'</span>选择</button></td></tr>';
				}
				$("#ajax-data").html(html);
			}
		}
	});
}

// 批量上传图片
function selectImgs(domId) {
    layer.open({
        id:'selectImgs',
        type : 2,
        title : '批量选择图片',
        maxmin : true,
        shadeClose : false,
        area : [ '90%', '90%' ],
        content : '/platform/config/batchUploadImg/' + domId // iframe的url
    });
}
function loadImgsInfo(domId, result) {
    if (!result || result.length <1) {
        parent.layer.msg("上传图片失败!",{icon:7});
        return;
    }
    $('#'+domId).val(result.join(","));
    /*var thumbUrl = result.split(",");
    for (var i = 0;i<thumbUrl.length;i++) {
    	var html = '<img class="img-responsive" id="categoryAddthumbImg" src="'+thumbUrl[i]+'" style="max-width: 30%">';
        $('#imgDiv').append(html);
    }*/

}

function onThumbBlur() {
	var url = $.trim($('#thumb').val());
	if (url) {
		if (url.indexOf("http") >= 0 || url.indexOf("https") >= 0) {
			$('#categoryAddthumbImg').attr('src', url);
		}else {
			var prefix = "http://pic.jinzhishenghuo.com";
			$('#categoryAddthumbImg').attr('src', prefix + url);
		}
	}
}

/**
 * 选择视频页面
 * @param inputId
 * @param imgId
 */
function onSelectImgBtnClick(inputId, imgId) {
	layer.open({
		id:'selectImg',
		type : 2,
		title : '选择视频',
		maxmin : true,
		shadeClose : false,
		area : [ '90%', '90%' ],
		content : '/platform/config/selectVideo/' + inputId +"/"+ imgId // iframe的url
	});
}

/**
 * 加载图片URL
 * @param inputId
 * @param imgId
 * @param url
 */
function loadImgUrl(inputId, imgId, url) {
	$('#'+inputId +'').val(url);
	//$('#'+imgId +'').attr('src', url);
}